package com.example.requestdemo.tasks;

import com.example.requestdemo.service.HttpApi;
import com.example.requestdemo.vo.ResponsesVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.DigestUtils;

import java.util.Objects;

/**
 * @author 86788
 */
@Slf4j
public class LoginTask implements Runnable {

    private HttpApi httpApi;

    private String password;

    public static final String CODE = "2000";

    public static final String ACCOUNT = "513027196911105824";

    public LoginTask(HttpApi httpApi, String password) {
        this.httpApi = httpApi;
        this.password = password;
    }

    @Override
    public void run() {
        String md5Password = DigestUtils.md5DigestAsHex(password.getBytes());
        ResponsesVo responsesVo = httpApi.login(ACCOUNT, md5Password);
        if (Objects.equals(responsesVo.getCode(), CODE)) {
            log.info("明文密码：【{}】，加密密码：【{}】，密码结果：【{}】", password, md5Password, responsesVo);
        } else {
            log.info("明文密码：【{}】，请求状态：【{}】", password, responsesVo.getCode());
        }
    }
}
